package indi.jp.project.business.yunying.controller;

import indi.jp.project.core.entity.JsonResult;
import indi.jp.project.core.util.SimpleEntityUtil;
import indi.jp.project.business.yunying.entity.FapiaoFiled;
import indi.jp.project.business.yunying.service.FapiaoFiledService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("/yunying/fapiao")
public class FapiaoFiledController {

    @Resource
    private FapiaoFiledService fapiaoFiledService;

    @GetMapping("/queryGrid")
    public JsonResult queryGrid(@ModelAttribute FapiaoFiled fapiaoFiled, HttpServletRequest request) throws Exception {
        SimpleEntityUtil<FapiaoFiled> simpleEntityUtil = new SimpleEntityUtil<>();
        fapiaoFiled = simpleEntityUtil.setBaseEntity(fapiaoFiled, request);
        return fapiaoFiledService.queryGrid(fapiaoFiled);
    }

    @PostMapping("/save")
    public JsonResult save(@RequestBody FapiaoFiled fapiaoFiled, HttpServletRequest request) throws Exception {
        SimpleEntityUtil<FapiaoFiled> simpleEntityUtil = new SimpleEntityUtil<>();
        fapiaoFiled = simpleEntityUtil.setBaseEntity(fapiaoFiled, request);
        return fapiaoFiledService.save(fapiaoFiled);
    }

    @GetMapping("/findById")
    public JsonResult findById(@RequestParam String id) throws Exception {
        return fapiaoFiledService.findById(id);
    }

    @PostMapping("/deleteById")
    public JsonResult delete(@RequestParam String id) throws Exception {
        return fapiaoFiledService.deleteById(id);
    }

}
